#include <stdio.h>
#include <pthread.h>

struct test
{
    int m_a;
    char m_ch;
};

void* thread_function1(void* arg);
void* thread_function2(void* arg);
//编译时gcc xx.c -pthread
int main()
{
    //1.创建一个线程
    pthread_t tid1;
    int ret = pthread_create(&tid1, NULL, thread_function1, NULL);
    if (ret == -1)
    {
        perror("create tid1 error");
        return -1;
    }

    struct test t;
    t.m_a = 1024;
    t.m_ch = 'a';

    pthread_t tid2;
    ret = pthread_create(&tid2, NULL, thread_function2, (void*)&t);
    if (ret == -1)
    {
        perror("create tid2 error");
        return -1;
    }

    //主程序
    while (1)
    {
        printf("xxx\n");
    }

}

void* thread_function1(void* arg)
{
    while (1)
    {
        printf("haha\n");
    }
}

void* thread_function2(void* arg)
{
    struct test* p = (struct test*)arg;
    while (1)
    {
        printf("main_a=%d\n", p->m_a);
        printf("main_ch==%c", p->m_ch);
    }
}
